import random
import pymysql
# for i in range(111.30, 113.09):
#     print('%04.3f' % random.random())

# 经度
l1 = ['%0.5f' % random.uniform(111.30, 113.09) for i in range(1000)]
# print(l1)
l2 = ['%0.5f' % random.uniform(37.27, 38.25) for i in range(1000)]
# print(l2)
#
# z = list(zip(l1, l2))
# print(len(z))
# print(z)




conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='mysql',db='ck_iot_B')
cur = conn.cursor()
for i in range(len(l1)):   #插入数据
  lng=random.choice(l1)
  lat = random.choice(l2)  # 在纬度列表中随机取一个
  cur.execute("insert into points(lng,lat) values(%s,%s)",(lng,lat))#注意用法
cur.execute('select * from points') #查询数据
for s in cur.fetchall():
  print(s)
conn.commit()
cur.close()



'''
东经111°30′～113°09′，北纬37°27′～38°25′
point: {
    lng: 112.638977,   //经度
    lat: 37.825733      //纬度
},

import random as r
import pymysql
first=('张','王','李','赵','金','艾','单','龚','钱','周','吴','郑','孔','曺','严','华','吕','徐','何')
middle=('芳','军','建','明','辉','芬','红','丽','功')
last=('明','芳','','民','敏','丽','辰','楷','龙','雪','凡','锋','芝','')
name=[]
passwd1=('1234','5678','147','258')
for i in range(101):
  name1=r.choice(first)+r.choice(middle)+r.choice(last) #末尾有空格的名字
  name2=name1.rstrip() #去掉末尾空格后的名字
  if name2 not in name: #名字存入列表中，且没有重名
    name.append(name2)
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123',db='test1')
cur = conn.cursor()
for i in range(len(name)):   #插入数据
  passwd=r.choice(passwd1)  #在密码列表中随机取一个
  cur.execute("insert into a2(name,passwd) values(%s,%s)",(name[i],passwd))#注意用法
cur.execute('select * from a2') #查询数据
for s in cur.fetchall():
  print(s)
conn.commit()
cur.close()
conn.close()
'''


